package com.itrip.search.controller;

import com.itrip.beans.dto.Dto;
import com.itrip.beans.vo.ParamVo;
import com.itrip.search.service.SearchService;
import com.itrip.search.vo.HotelParam;
import com.itrip.search.vo.ItripHotelVO;
import com.itrip.utils.DtoUtil;
import com.itrip.utils.PageBean;
import org.apache.solr.client.solrj.SolrQuery;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.client.solrj.impl.XMLResponseParser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/hotellist")
public class SearchController {

    @Autowired
    private SearchService searchService;

    @PostMapping("/searchItripHotelListByHotCity")
    public Dto searchItripHotelListByHotCity(@RequestBody ParamVo paramVo){
        try {
            List<ItripHotelVO> list = searchService.searchItripHotelListByHotCity(paramVo.getCityId(),paramVo.getCount());
            return DtoUtil.returnDataSuccess(list);
        } catch (Exception e) {
            return DtoUtil.returnFail(e.getMessage(),"50001");
        }
    }

    @PostMapping("/searchItripHotelPage")
    public Dto searchItripHotelPage(@RequestBody HotelParam hotelParam){
        try {
              PageBean  pageBean = new PageBean();
              if(hotelParam.getPageNo() == null){
                  hotelParam.setPageNo(1);
              }
                pageBean.setCurPage(hotelParam.getPageNo());
                pageBean.setPageSize(2);
                searchService.searchItripHotelPage(hotelParam,pageBean);
                return DtoUtil.returnDataSuccess(pageBean);
        } catch (Exception e) {
            return DtoUtil.returnFail(e.getMessage(),"50001");
        }
    }

}
